<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name='viewport' content='width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no'/>
<title>门店管理</title>
<link href="<{$env.app.res_url}>/css/global.css" rel="stylesheet" />
<script language="javascript" type="text/javascript" src="<{$env.app.res_url}>/js/moo.js"></script>
</head>
<body>
    <div class="bodyer-header clearfix">
        <div class="top_menu"><a href="<{$delivery_link.confirm}>"><icon></icon><span>进入确单页面</span></a></div>
        <div class="top_logout"><a href="<{$delivery_link.logout}>"><icon></icon><span>退 出</span></a></div>
    </div>
    <div class="bodyer-main">
        <form id="delivery_frm" name="delivery_frm" method="post" action="<{$delivery_link.dispose}>" class="delivery_frm" >
            <div class="search-areas">
                <ul class="search-conditions clearfix">
                    <li>
                        <label class="delivery_bn"></label><input autofocus type="text" required="true" name="delivery_bn" id="delivery_bn" value="发货单号" class="gray" />
                    </li>
                    <{if $code_html_show}>
                    <li>
                        <label class="check_code"></label><input autofocus type="text" required="true" name="check_code" id="check_code" value="校验码" class="gray" />
                    </li>
                    <{/if}>
                </ul>
                <ul>
                    <li class="search-btn">
                       <button id="btn-search" type="button" class="confirm-common-btn">
                        <span>
                            <span><{t}>确认收货<{/t}></span>
                        </span>
                      </button>
                      <{if $code_html_show}>
                           <button id="btn-resend" type="button" class="confirm-common-btn" onClick="ajax_resend_msg()">
                            <span>
                                <span><{t}>重新生成校验码<{/t}></span>
                            </span>
                          </button>
                      <{/if}>
                    </li>
                </ul>
            </div>

            <div class="dly_bills">
                <div id="result_confirm" class="delivery_item">&nbsp;</div>
            </div>

            <!--
            <div class="bottom_btns clearfix">
                <li class="click_link"><a href="<{$delivery_link.confirm}>">进入确单页面</a></li>
                <li><a href="<{$delivery_link.logout}>">退 出</a></li>
            </div>
            -->

        </form>
    </div>
    <{include file="alert_msg.html"}>

<script type="text/javascript">
(function(){
    //判断是否开启销单校验码 关闭状态$('check_code')不存在
    if($('check_code'))
    {
        $('check_code').addEvent('focus',function(e)
        {
            if($('check_code').value == "校验码")
            {
                $('check_code').value = "";
                $('check_code').className = "black";
            }
        });
        $('check_code').addEvent('blur',function(e)
        {
            if($('check_code').value == "")
            {
                $('check_code').value = "校验码";
                $('check_code').className = "gray";
            }
        });
        $('check_code').addEvent('keypress',function(e){
            if(e.code == 13){
                  search_delivery_bn('false');
            }
        });
        
        $('check_code').addEvent('keyup',function(e){
            show_delivery_info();
        });
        
    }
        
    $('btn-search').addEvent('click', function(){
        search_delivery_bn('false');
    });
    
    $('delivery_bn').addEvent('keypress',function(e)
    {
        if($('delivery_bn').value == "发货单号")
        {
            $('delivery_bn').value = "";
            $('delivery_bn').className = "black";
        }
    });
    $('delivery_bn').addEvent('click',function(e)
    {
        if($('delivery_bn').value == "发货单号")
        {
            $('delivery_bn').value = "";
            $('delivery_bn').className = "black";
        }
    });
    $('delivery_bn').addEvent('blur',function(e)
    {
        if($('delivery_bn').value == "")
        {
            $('delivery_bn').value = "发货单号";
            $('delivery_bn').className = "gray";
        }
    });
    $('delivery_bn').addEvent('keyup',function(e){
        show_delivery_info();
    });
    
})();

function show_delivery_info(){
    
    //keyup事件显示发货单信息 发货单长度为14位 即完整的发货单号 才要求显示发货单信息
    delivery_bn    = $("delivery_bn").value;
    var delivery_bn_length = $("delivery_bn").value.length;

    if(delivery_bn_length != 14 ){
        return false;
    }
    
    //开启销单校验码才进行校验码验证
    if($('check_code')){
        check_code = $("check_code").value;
        if(check_code.length == 6){
            search_delivery_bn('true');
        }
    }else{
        search_delivery_bn('true');
    }
    
}

function search_delivery_bn(flag)
{
    var dly_frm = document.delivery_frm;
    
    delivery_bn    = $("delivery_bn").value;
    if(delivery_bn == "" || delivery_bn == "发货单号"){
        alert_msg("请填写发货单号");
        return false;
    }
    
    //开启销单校验码才进行校验码验证
    var check_code = "";
    if($('check_code')){
        check_code = $("check_code").value;
        if(check_code == "" || check_code == "校验码"){
            alert_msg("请填写校验码");
            return false;
        }
    }

    $('btn-search').set('disabled', 'true');

    new Request({
        url: "<{$delivery_link.ajaxDly}>",
        async:false,
        method:'post',
        data:{delivery_bn:delivery_bn, check_code:check_code, flag:flag},
        onComplete: function(json)
        {
            json = JSON.decode(json);
            $("result_confirm").innerHTML = '';

            if(!json.res){
                json.msg = '操作失败';
            }

            if(json.msg){
                alert_msg(json.msg);
            }

            if(json.res == 'ajaxload'){
                result_html   = '<div class="ship_name clearfix"><icon></icon>收件人：' + json.result.consignee.name + '　手机号：' + json.result.consignee.mobile +'</div>';

                if(json.result.consignee.telephone){
                    result_html   += '<div class="ship_tel clearfix"><icon></icon>收件人电话：' + json.result.consignee.telephone +'</div>';
                }

                result_html   += '<div class="ship_type clearfix"><icon></icon>订单交付方式：' + json.result.logi_name +'</div>';
                result_html   += '<div class="store_name clearfix"><icon></icon>门店名称：' + json.result.store_name +'</div>';
                result_html   += '<div class="store_mobile clearfix"><icon></icon>门店手机号：' + json.result.mobile +'</div>';

                if(json.result.tel){
                    result_html   += '<div class="store_tel clearfix"><icon></icon>门店电话：' + json.result.tel +'</div>';
                }

                result_html   += '<div class="store_addr clearfix"><icon></icon>门店地址：' + json.result.store_addr +'</div>';
                result_html   += '<div class="order_bn clearfix"><icon></icon>订单号：' + json.result.order_info.order_bn +'</div>';
                $("result_confirm").innerHTML = result_html;
            }else{
                $("result_confirm").innerHTML = '';
                $("delivery_bn").value = '发货单号';
                $("check_code").value = '校验码';
            }
        }
    }).send();

    $('btn-search').set('disabled', '');
}

function ajax_resend_msg()
{
    var dly_bn = $('delivery_bn').value;
    if(dly_bn == "" || dly_bn == "发货单号")
    {
        alert_msg("请填写发货单号");
        return false;
    }

    $('btn-resend').set('disabled', 'true');

    new Request(
    {
        url: "<{$delivery_link.sendMsg}>",
        async:false,
        method:'post',
        data:{delivery_bn:dly_bn},
        onComplete: function(json)
        {
            json = JSON.decode(json);
            var msg = json.msg ? json.msg : '操作失败';

            $('btn-resend').set('disabled', '');

            alert_msg(msg);
        }
    }).send();
}
</script>
</body>
</html>
